package com.next.aap.server.tasks;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

@Component
public class TaskManager implements ApplicationContextAware{

	private ApplicationContext applicationContext;
	
	@Autowired
	@Qualifier(value="httpRequestExecutor")
	private ThreadPoolTaskExecutor threadPoolTaskExecutor;

	public void runSendMessageTask(String messageType,Object message){
		SendMessageTask sendMessageTask = applicationContext.getBean(SendMessageTask.class);
		sendMessageTask.setMessageType(messageType);
		sendMessageTask.setMessage(message);
		
		threadPoolTaskExecutor.execute(sendMessageTask);
	}
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		this.applicationContext = applicationContext;
		
	}
}
